package com.hubei.car.controller;

import com.hubei.car.annotation.DeleteApi;
import com.hubei.car.annotation.GetApi;
import com.hubei.car.annotation.PostApi;
import com.hubei.car.dto.req.PageCondition;
import com.hubei.car.entity.CarClassify;
import com.hubei.car.entity.Result;
import com.hubei.car.service.CarClassifyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.validation.Valid;


/**
 * 一二级分类控制层
 * @author luokangtao
 * @create 2019-08-30 12:35
 */
@RestController
@Slf4j
//@RequestMapping("/classify")
@Api(value = "分类管理",tags = "分类管理")
public class CarClassifyController {

    @Autowired
    private CarClassifyService classifyService;

    @PostApi(value = "/add",auth = false)
    @ApiOperation("添加分类")
    public Result add(@RequestBody  CarClassify carClassify){
        return Result.ok(classifyService.add(carClassify));
    }

    @PostApi(value = "/update",auth = false)
    @ApiOperation("根据主键ID修改")
    public Result update(@RequestBody CarClassify carClassify){
        return Result.ok(classifyService.update(carClassify));
    }

    @DeleteApi(value = "/deleteOne/{id}",auth = false)
    @ApiOperation("根据主键ID删除")
    public Result deleteOne(@PathVariable("id") Long id){
        return Result.ok(classifyService.deleteOne(id));
    }

    @GetApi(value = "/queryOne/{id}",auth = false)
    @ApiOperation("根据主键ID查询")
    public Result queryOne(@PathVariable("id") Long id){
        return Result.ok(classifyService.queryOne(id));
    }

    @PostApi(value = "/queryOneAll",auth = false)
    @ApiOperation("条件查询一级分类")
    public Result queryOneAll(@RequestBody @Valid PageCondition pageCondition){
        return Result.ok(classifyService.queryAll(pageCondition,1));
    }

    @PostApi(value = "/queryTwoAll",auth = false)
    @ApiOperation("条件查询二级分类")
    public Result queryTwoAll(@RequestBody @Valid PageCondition pageCondition){
        return Result.ok(classifyService.queryAll(pageCondition,2));
    }



}
